home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / emulator / bsvc-1.000 / bsvc-1 / bsvc-1.0.4 / src / UI / listing.tk < prev    next >
Text File  |  1995-07-26  |  6KB  |  166 lines

  1. ###############################################################################
  2. # $Id: listing.tk,v 1.3 1995/06/30 17:20:20 bmott Exp $
  3. ###############################################################################
  4. # listing.tk - Routines to handle the program listing window
  5. #
  6. # Copyright 1993
  7. # Bradford W. Mott
  8. # November 13,1993
  9. ###############################################################################
  10. # $Log: listing.tk,v $
  11. # Revision 1.3  1995/06/30  17:20:20  bmott
  12. # Problem with selecting cancel when loading a file fixed
  13. # (Used to wipe out the address table!)
  14. #
  15. # Revision 1.2  1994/09/13  23:27:14  bmott
  16. # Changed the file selector calls to use BtkFileSelector
  17. # Modified the algorithm to select lines to highlight
  18. #
  19. # Revision 1.1  1994/02/18  20:29:21  bmott
  20. # Initial revision
  21. #
  22. ###############################################################################
  23.  
  24. ###############################################################################
  25. # Refresh the listing 
  26. ###############################################################################
  27. proc RefreshProgramListing {} {
  28.   global programListingAddressTable
  29.  
  30.   ## Make sure the program listing window exists
  31.   if {[winfo exists .programListing]==0} {return}
  32.  
  33.   ## Get the Program Counter's name
  34.   PutLine "ListPCRegisterName"
  35.   set pc_name [lindex [GetList] 0]
  36.  
  37.   ## Get the Program Counter's value
  38.   PutLine "ListRegisterValue $pc_name"
  39.   scan [lindex [GetList] 0] "%s" pc
  40.   set pc [string tolower $pc]
  41.  
  42.  
  43.   ## Remove highlight from old lines
  44.   .programListing.pack.text tag remove LineSelectTag 0.0 end
  45.  
  46.   ## Highlight each of the lines
  47.   catch {
  48.     foreach i $programListingAddressTable($pc) {
  49.       .programListing.pack.text tag add LineSelectTag $i.0 $i.1000
  50.     }
  51.  
  52.     ## Move the view to the last highlighted line
  53.     .programListing.pack.text yview -pickplace [expr $i].0
  54.   }
  55.  
  56. }
  57.  
  58. ###############################################################################
  59. # Load a listing into the text window
  60. ###############################################################################
  61. proc LoadProgramListing {} {
  62.   global programListingAddressTable
  63.  
  64.   set name [BtkFileSelector -text "Select program listing to load:" \
  65.       -in .programListing]
  66.  
  67.   if {$name!=""} {
  68.     if {[file isdirectory $name]} {
  69.       ChildAlertDialog ".programListing" {ERROR: The name specified was a directory!!!}
  70.       return
  71.     }
  72.  
  73.     if {[file exists $name]==0} {
  74.       ChildAlertDialog ".programListing" {ERROR: That file does not exists!!!}
  75.       return
  76.     }
  77.  
  78.     ## Remove the Address Table array 
  79.     catch {unset programListingAddressTable}
  80.  
  81.     ## Open the file
  82.     set file [open $name]
  83.  
  84.     ## Empty the text widget
  85.     .programListing.pack.text delete 1.0 end
  86.  
  87.     .programListing.pack.text insert end "\nFile: $name\n\n"
  88.     .programListing.pack.text tag add FilenameTag "end - 2 line linestart" \
  89.         "end - 2 line lineend" 
  90.  
  91.     ## Insert listing in the text widget 
  92.     while {1} {
  93.       if {[gets $file line] != "-1"} {
  94.         if {[scan $line "%s" address] == "1"} {
  95.           set address [string tolower $address]
  96.           scan [.programListing.pack.text index end] "%d" lineNumber
  97.           .programListing.pack.text insert end "$line\n"
  98.           catch {lappend programListingAddressTable($address) $lineNumber}
  99.         }
  100.       } else {
  101.         break
  102.       }
  103.     }
  104.     close $file
  105.  
  106.     RefreshProgramListing
  107.   }
  108. }
  109.  
  110. ###############################################################################
  111. # Close the program listing window
  112. ###############################################################################
  113. proc CloseProgramListing {} {
  114.   catch {destroy .programListing}
  115. }
  116.  
  117. ###############################################################################
  118. # Create and display the program listing window
  119. ###############################################################################
  120. proc OpenProgramListing {} {
  121.   global ProgramListing
  122.  
  123.   ## Destroy the window if it exists
  124.   catch {destroy .programListing}
  125.  
  126.   ## Create the top level window
  127.   toplevel .programListing
  128.   wm title .programListing "Program Listing"
  129.   wm iconname .programListing "Program Listing"
  130.   wm grid .programListing 1 1 1 1
  131.  
  132.   ## Create the text widget to display the program listing in
  133.   frame .programListing.pack
  134.     text .programListing.pack.text -relief raised -borderwidth 2 \
  135.        -cursor left_ptr -wrap none \
  136.        -yscrollcommand ".programListing.pack.yscroll set"
  137.     .programListing.pack.text tag configure LineSelectTag -foreground White \
  138.         -background Black
  139.     .programListing.pack.text tag configure FilenameTag -foreground Red \
  140.         -underline 1
  141.     bind .programListing.pack.text <Any-KeyPress> "NOP"
  142.     bind .programListing.pack.text <Any-ButtonPress> "NOP"
  143.     bind .programListing.pack.text <Any-Motion> "NOP"
  144.     bind .programListing.pack.text <Any-Double-ButtonPress> "NOP"
  145.  
  146.     ## Create scroll bar for text window
  147.     scrollbar .programListing.pack.yscroll -relief raised \
  148.         -command ".programListing.pack.text yview"
  149.     pack .programListing.pack.yscroll -side left -fill y
  150.     pack .programListing.pack.text -side left -fill both -expand 1
  151.  
  152.   ## Create buttons
  153.   button .programListing.load -text "Load..." \
  154.       -command {LoadProgramListing}
  155.   button .programListing.clear -text "Clear" \
  156.       -command {.programListing.pack.text delete 1.0 end}
  157.   button .programListing.dismiss -text "Dismiss" \
  158.       -command CloseProgramListing
  159.  
  160.   pack .programListing.pack -side top -fill both -expand 1 -padx 2 -pady 2
  161.   pack .programListing.load -side left -fill x -expand 1 -padx 4 -pady 2
  162.   pack .programListing.clear -side left -fill x -expand 1 -padx 4 -pady 2
  163.   pack .programListing.dismiss -side left -fill x -expand 1 -padx 4 -pady 2
  164. }
  165.  
  166.